import urllib.request
import json
import jsonpath

url = 'https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1742449315686_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'

headers = {
    'accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    'bx-v': '2.5.28',
    'cache-control': 'no-cache',
    'cookie': 'cna=P3erH3MlhBcCAcpvGAK3pJEh; thw=cn; t=366a82e4a661b9b8e4bedd3bf3c9ff6c; _tb_token_=f3e7858587345; _samesite_flag_=true; cookie2=10826845e1601bca03a244d7ad7128c2; tfstk=gSxjZPYWsSVfGyhMrIDPOpzNbAIsCYoUcR69KdE4BiIY65pdalkc0Vj61_OGgZSvfUq6KdxqnGkcmKjGXXlEY19DnG4f8ZzXfgCRK9nNBNQOmgFnyZV-YDJDn-WxLLne0DOw6_aTXCQAyTBcwtEABNH5y9WOXoQTDzFRZ_COXsE9e8BCHlUOBCp-FOfR6GI96ahzuJ6slsvjh_kYymlCKKC7XlKxjZ1B8Pr_f36flHvANE82Vt_f9aALjwtvadK2ma0uzGvyRCT99bzVMe6BNw8jOoOBiOd50HHioab9fh6krfa1OFp2-FQSHmp5csOBqQeTliT9ih_DlRDHeidk-6bxrbXW0H71taN-MLJ5MwT6gbqOge9JNw-zakSp-Qt1JMIPgk5IkrU_Fwq1F6kSFP4MgmuTj6dIJLbAEt_rFYNvSZBlF6kSFP4GkTXfaYM7MFf..; v=0; xlly_s=1; tb_city=320500; tb_cityName="y9XW3Q=="; isg=BPT0IhwyL_y77btPtwV4S_TuxbJmzRi30RY0HI5VRH8C-ZRDtt9-R_a_eTEhBlAP',
    'pragma': 'no-cache',
    'priority': 'u=1, i',
    'referer':'https://dianying.taobao.com/?spm=a1z21.3046609.city.1.32c0112a3DGlPd&city=110100',
    'sec-ch-ua':'"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest'
}

request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
# print(content)
content = content.split('(')[1].split(')')[0]
# print(content)
with open('city.json', 'w',encoding='utf-8') as f:
    f.write(content)

obj = json.load(open('city.json','r',encoding='utf-8'))
city_list = jsonpath.jsonpath(obj, '$..regionName')

print(city_list)
